package icu.mohan.erp.call.util;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import com.alibaba.fastjson2.JSONObject;

import icu.mohan.erp.call.model.CallbackAccountReview;
import icu.mohan.erp.call.model.CallbackRecord;
import icu.mohan.erp.call.model.CallbackSeat;

/**
 * 请求参数转换工具类
 *
 * @author yanglihao
 */
public class ParamUtil {

    /**
     * 子账号回调
     */
    public static final CallbackAccountReview accountReviewParam(JSONObject param) {
        Long childAccountNo = param.getLong("childAccountNo");
        Integer auditFlag = param.getInteger("auditFlag");
        String auditMessage = param.getString("auditMessage");
        return CallbackAccountReview.builder().childAccountNo(childAccountNo).auditFlag(auditFlag)
            .auditMessage(auditMessage).build();
    }

    /**
     * 坐席回调
     */
    public static final CallbackSeat seatParam(JSONObject param) {
        Long seatNo = param.getLong("seatNo");
        Integer auditFlag = param.getInteger("auditFlag");
        String auditMessage = param.getString("auditMessage");
        return CallbackSeat.builder().seatNo(seatNo).auditFlag(auditFlag).auditMessage(auditMessage).build();
    }

    /**
     * 话单回调
     */
    public static final CallbackRecord recordParam(JSONObject param) {
        Integer type = param.getInteger("type");
        String serialNumber = param.getString("serialNumber");
        String seatTel = param.getString("seatTel");
        String toPhone = param.getString("toPhone");
        String startTimeString = param.getString("startTime");
        LocalDateTime startTime = LocalDateTime.parse(startTimeString, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
        String endTimeString = param.getString("endTime");
        LocalDateTime endTime = LocalDateTime.parse(endTimeString, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
        Integer callSecond = param.getInteger("callSecond");
        String recordUrl = param.getString("recordUrl");
        return CallbackRecord.builder().type(type).serialNumber(serialNumber).seatTel(seatTel).toPhone(toPhone)
            .startTime(startTime).endTime(endTime).callSecond(callSecond).recordUrl(recordUrl).build();
    }
}
